INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

variable undefined

variable undefined

(OP)
I have script:
$("#consigneeBtn").on('click', function() { var id = document.getElementById('consignee').value;
})

Markup:
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> <a href="{{URL::to('consignees/', id)}}">
<button type="button" class="btn btn-default" id="consigneeBtn">Consignee</button> </a> The variable id has the value(I checked with alert) but I get UNDEFINED VARIABLE ID when I run my page

RE: variable undefined

Firstly, if you have the JQuery framework loaded, you should try to use it for all JS syntax..

CODE

var id = document.getElementById('consignee').value 
should be...

CODE

var id = $('#consignee').val(); 

Though looking at the mark-up I cannot see any element that has an id = consignee?
Were do you get Undefined Variable?
What is meant to be the value of id?


"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music

RE: variable undefined

that error looks more like php. not javascript.

remember that javascript sits client side and you button click event is client side.
php sits server side. it cannot know anything about the client side until the client side tells it. that is typically at page refresh time or on an ajax submission of some form.

i suspect that you want to set the href of the <a> dynamically. work from that perspective instead.

RE: variable undefined

(OP)
The Variable I'd is the value of the query containing the key for a consignee. I want to grab that value and then lookup that consignee for more information. With that info to go to a json array. With that array I will parse and place into text boxes for display.

RE: variable undefined

where is the variable defined?
the only place i can see is by this reference:

CODE

document.getElementById('consignee') 

however i cannot see any element with the id of consignee.

and i repeat that the error appears to be more php than javascript. so i suspect you are trying to output data from php in some manner that is not working.

your response was not clear enough for me to work out what you meant.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close