0

Sorry - still a beginner - How do I dynamically create action url using the input text from the user?

 <form name="myInstitution"  action="" method="GET">
        <div>
            <label for="names" class="bold">Institution Name</label>
            <input id="names" name="schoolName" type="text"></input>                

        </div>

        <div class="bold"></div>

        <div>
            <input type="submit" value="Submit" id="sbutton" name="submit" />
            <input type="reset" value="Reset" />
        </div>
    </form>
2
  • Where do you want the action to come from? schoolName input? Commented Feb 18, 2013 at 4:47
  • @explosion pills -- yes! exactly! Commented Feb 18, 2013 at 4:54

2 Answers 2

1

Since you don't seem to be using a javascript library, I'll copy the bind code in pure javascript from this answer.

var on = (function(){
    if ("addEventListener" in window) {
        return function(target, type, listener){
            target.addEventListener(type, listener, false);
        };
    }
    else {
        return function(object, sEvent, fpNotify){
            object.attachEvent("on" + sEvent, function(){
                fpNotify(window.event);
            });
        };
    }
}());


on(document.getElementById("sbutton"), "click", function(){
    this.action = document.getElementById( "names" ).val() + ".ext";
});

If you were using a javascript library like jQuery, you could bind to the event handler like this:

$( "form[name=\"myInstitution\"]" ).on( "submit", function( e ){
    var $this = $(this),
        text  = $this.find( "input#names" ).val();

    $this.prop( "action", text + ".ext" );
});
Sign up to request clarification or add additional context in comments.

Comments

1
$('#myForm').submit(function ()
{
    var action = '';
    // compute action here...
    $(this).attr('action', action);
});

Hope it will help you..

2 Comments

@sasu why is the word event in the argument for the function?
i had edited the code..thats no need..is this worked for you?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.