1779 Posts in 582 Topics by 556 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 284 Views |
-
Need help working with forms and Javascript

7 December 2012 at 2:12pm Last edited: 7 December 2012 2:24pm
Hi all,
I have been trying to get my head around this for awhile now, but cant seem to work out this last little bit.
Let me explain what I'm doing.
I have an events page where someone can enrol for an event, when they click "Enrol" it takes them to a form which has been populated with things like the date, location, etc for the event. They can then enter missing details like their names, email address, etc.
I am using the following to achieve the above:
//Function for adding subject to subject box
if($('#Form_Form').length > 0){
var course = decodeURIComponent($.getUrlVar('cour'));
var date = decodeURIComponent($.getUrlVar('date'));
var time = decodeURIComponent($.getUrlVar('time'));
var loc = decodeURIComponent($.getUrlVar('loc'));
var price = decodeURIComponent($.getUrlVar('price'));
if(course != 'undefined'){
$('#EditableRadioField39').hide();
$('#Form_Form_EditableTextField40').val(course);
} else {
$('#EditableTextField40').hide();
}
if(date != 'undefined'){
$('#Form_Form_EditableDateField13').val(date);
}
if(time != 'undefined'){
$('#Form_Form_EditableTextField12').val(time);
}
if(loc != 'undefined'){
$('#Form_Form_EditableTextField14').val(loc);
}
if(price != 'undefined'){
$('#Form_Form_EditableTextField36').val(price);
}
}The only issue I have is that I need to make something that changes the price dependent on how many people sign up for the event.
I cant seem to create a new function which works.
how can I work out if a EditableTextField has nothing assigned to it?
The following is what I am trying:
if($('#EditableTextField21').var != ''){
$('#Form_Form_EditableTextField36').val(price*2);
}EditableTextField21 is a text field for the persons Name.
EditableTextField36 is a field for the price. -
Re: Need help working with forms and Javascript

8 December 2012 at 4:37pm
$('#EditableTextField21').var should be $("#EditableTextField21").val();
-
Re: Need help working with forms and Javascript

12 December 2012 at 10:51am Last edited: 12 December 2012 11:01am
you're right, my mistake.
-
Re: Need help working with forms and Javascript

12 December 2012 at 11:05am
Hi Willr,
It works!
However it doesn't automatically update when something is entered into "#EditableTextField21".
Am I expecting too much from javascript?Thanks
-helenclarko -
Re: Need help working with forms and Javascript

13 December 2012 at 7:58pm
However it doesn't automatically update when something is entered into "#EditableTextField21".
Make sure you function is included within a change event that is fired when you edit the field.
$("#EditableTextField21").change(function() {
// do something
});Lot's of docs on the web for how to use events in javascript - http://www.codecademy.com/courses/jquery-events/1#!/exercises/0
| 284 Views | ||
|
Page:
1
|
Go to Top |


