PDA

View Full Version : Autofilling Form based on page name


cocoonfx
10-22-2010, 09:02 AM
Hi

I have a training page say called "clean.html" and I have a link to a booking form which have a field called Course Name. Is there a way I can get the form to automatically fill the Course Name.

i.e

clean.html ---> Bookingform.html will show in form Course Name = clean
water.html ---> Bookingform.html will show in form Course Name = water

Any suggestions would be appreciated.

edbr
10-22-2010, 09:08 AM
im pretty sure javascript could do this, get page name then a conditional clause to enter , have to yahoogle and see if you can track those two events down i think

ranjan
10-22-2010, 10:22 PM
Hi

......snip.....

clean.html ---> Bookingform.html will show in form Course Name = clean
water.html ---> Bookingform.html will show in form Course Name = water

Any suggestions would be appreciated.


jQuery.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (!results) { return 0; }
return results[1] || 0;
}

$(function(){
var course = $.urlParam('course');
$('#txtCourseName').val(course);
});


Link on clean.html goes to bookingform.html?course=clean
Link on water.html goes to bookingform.html?course=water

The code will fill up a text field with id txtCourseName with appropriate course name

gentleone
10-23-2010, 09:27 AM
jQuery.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (!results) { return 0; }
return results[1] || 0;
}

$(function(){
var course = $.urlParam('course');
$('#txtCourseName').val(course);
});


Hi Ranjan,

I was looking for this too, but it has to autofill a select box instead of an input field. The above doesn't work on select boxes. Is there a way to autofill select boxes?

ranjan
10-23-2010, 06:30 PM
Hi Ranjan,

I was looking for this too, but it has to autofill a select box instead of an input field. The above doesn't work on select boxes. Is there a way to autofill select boxes?

Use:


<option value="clean">Clean</option>
<option value="water">Water</option>


Note that code below changes values which are "clean" and "water" and not "Clean" and "Water"

$('#mySelectBox').val(course);

gentleone
10-23-2010, 07:56 PM
Use:


<option value="clean">Clean</option>
<option value="water">Water</option>
Note that code below changes values which are "clean" and "water" and not "Clean" and "Water"

$('#mySelectBox').val(course);


Thanks a lot, Ranjan! I see it's actually a logic way. :)