AbydosGater Posted July 18, 2007 Share Posted July 18, 2007 Hi guys, Here, i am really stuck as dont know anything about javascript. I am writing a form.. and one of the fields in the form is going to be for "Your Domain". What i need help on, is figuring out.. when a user puts say.. domain.com in the box.. That the forms "action=" method is changed to the domain ie: <form action="domain.com/process_form">.. Javascript is the only way i can thing about doing this.. But i dont know Javascript. Could someone please help me! Andy Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 18, 2007 Share Posted July 18, 2007 you could make a simple javascript function like so: function submitForm(formid, actionURL) { form_handle = document.getElementById(formid); form_handle.action = actionURL; form_handle.submit(); return true; } and in the form's submit button, use: <input type="submit" name="Your Domain" onclick="javascript:submitForm(thisformsid, 'domain.com/process_form');" /> the reason we still use a submit input type is so that those with javascript can still submit the form - it'll just head to the form's default action. Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted July 18, 2007 Author Share Posted July 18, 2007 Yes, i would need something like this. But not exact, I need to get it so that it submits to a domain that the user has entered in another text field. Would you know how this is done? Andy Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 18, 2007 Share Posted July 18, 2007 let's assume the ID of our input textbox is called "targetDomain" and that our form's ID is "formOfMysteryAndWonder": function customSubmit() { form_handle = document.getElementById("formOfMysterAndWonder"); custom_action = document.getElementById("targetDomain").value; if (custom_action != '') { form_handle.action = custom_action; form_handle.submit(); return true; } else { return false; } } submit button: <input type="submit" name="do_this_thang" value="Go To Your Domain" onclick="return customSubmit();" /> give this a shot. i have a habit of needing to troubleshoot my javascript functions, so it may not work out of the box, to warn you. Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted July 18, 2007 Author Share Posted July 18, 2007 Hmm sorry. It didnt work. Its just submitting like it always does normally. Andy Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 18, 2007 Share Posted July 18, 2007 alright, well we might as well just drop the submit accessibility to do some bug checking: function customSubmit() { form_handle = document.getElementById("formOfMysterAndWonder"); custom_action = document.getElementById("targetDomain").value; if (custom_action != '') { form_handle.action = custom_action; form_handle.submit(); } } <input type="button" name="do_this_thang" value="Go To Your Domain" onclick="customSubmit();" /> keep in mind the javascript console in FF is extremely handy for javascripting. Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted July 18, 2007 Author Share Posted July 18, 2007 Ah sorry. My fault i mistyped something. All fixed.. And its redirecting now! Very very nice Thank you soo much! Andy Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted July 18, 2007 Author Share Posted July 18, 2007 Hey again, Sorry have not this one yet.. One last question.. I cant find javascript string interpolation on any of the tutorials i have checked.. when you set the action:" form_handle.action = custom_action;" How can i add information around the custom_action? Like .'/dir/'. In PHP.. I tried that but failed.. Any idea? Thanks Andy Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 19, 2007 Share Posted July 19, 2007 the concatenation in javascript is a little unfamiliar - you have to use + signs in order to achieve it: form_handle.action = custom_action + "/dir/" + some_var; Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted July 19, 2007 Author Share Posted July 19, 2007 Yay! Thank you so much.. All working now! Your a real life saver! Ever anything i can do to repay you just let me know! Andy Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.