Skip to content Skip to sidebar Skip to footer

Pass Javascript Variables To Form/input Fields As Onsubmit Href Link

id like to have an input box that a user can enter a search term into that gets passed to maybe a javascript function that then combines some url segments with the search term crea

Solution 1:

Maybe something like:

<form action="" onSubmit="urlGen(this);" method="get" target="_blank">
    <inputtype="text"id="intranet"size="15"value="Search Intranet.."onFocus="this.value = ''"onBlur="this.value = 'Search Intranet..'" / ></form>functionurlGen(f){
   var i1 = 'urlSeg1';
   var i2 = f.intranet.value;
   var i3 = 'urlSef';
   f.action = i1 + i2 + i3;
   returntrue;
}

Solution 2:

Use form's onSubmit event where set the appropriate data to the intranet's input - don't change this.href (form does not have such attribute). Remember though that JavaScript can be disabled at the client's side. Consider also placing hidden inputs into the form for i1 and i2 and do all combination logics at the server side.

<formaction=""onSubmit="urlGen()">
...
</form><scriptlanguage="javascript"type="text/javascript">functionurlGen()
                        {


                            var i1 = "urlSeg1";
                            var i2 = document.getElementById('intranet').value;
                            var i3 = "urlSef2";

                            document.getElementById('intranet').value = i1 + i2 + i3;


                        }
                </script>

Solution 3:

should also note that this is for a sidebar gadget and just needs to work with ie and server/client limitations is null. tried both of those methods (i think - still a beginner), but all that happens when i hit enter is the page reloads (target="_blank" opens new page of the same).

id like to do away with the submit button area entirely, but it is functional with that and without the form tags.

what i have right now:

<divid="row2"><scriptlanguage="javascript"type="text/javascript">functionurlGen(f)
                        {
                            var i1 = "seg1";
                            var i2 = f.intranet.value;
                            var i3 = "seg2";

                            var fullURL = i1 + i2 + i3;
                            f.action = i1 + i2 + i3;

                            returntrue;
                        }
                </script><!-- Intranet Search --><formaction=""onSubmit="urlGen(this)"method="post"target="_blank"><inputtype="text"id="intranet"size="15"value="Search Intranet.."onFocus="this.value = ''"onBlur="this.value = 'Search Intranet..'" / ></form><br><br><ahref="javascript: void(0)"onClick="this.href = i1 + document.getElementById('intranet').value + i3"target="_blank"><divid="submit"class="out"onMouseOver="document.getElementById('submit').className = 'over';"onMouseOut="document.getElementById('submit').className = 'out';"><span>Submit</span></div></a></div>

Post a Comment for "Pass Javascript Variables To Form/input Fields As Onsubmit Href Link"