Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable undefined

Status
Not open for further replies.

dendic

Programmer
Jan 19, 2003
106
0
0
US
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
 
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
 
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.
 
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.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top