tags:

views:

36

answers:

6

Hi, i have this form:

<form action = "" method = "get">
<input type = "input" name = "id" value = "3" />
<input type = "input" name = "name" value = "gloris" />
<input type = "submit" class = "button_big" name = "submit" value = "SEND" />
</form>

And how make this link (and i must use button): www.link.com/3/gloris

+1  A: 
<form action="http://www.link.com/3/gloris" method="get">
<input type="submit" value="Go to gloris" />
</form>
Novikov
I doubt he wants to hard-code the link. Presumably, those values are just the defaults.
Matthew Flaschen
Its good decision for my, thanks ;). But now url looks like:http://www.link.com/3/gloris?submit=Go to gloris, how disabled this: "submit=Go to gloris" ?
+2  A: 

As Felix says, this requires JavaScript. It would be something like:

<script type="text/javascript">
window.addEventListener("load", function()
{
  document.getElementById("myForm").addEventListener("submit", function()
  {
    var id = document.getElementById("id").value;
    var name = document.getElementById("name").value;
    window.location = [window.location.replace(/\/$/, ''), id, name].join("/");
  }, false);
}, false); 
</script>

<form action = "" id = "myForm" method = "get">
<input type = "text" name = "id" id = "id"  value = "3" />
<input type = "text" name = "name" id = "name" value = "gloris" />
<input type = "submit" class = "button_big" name = "submit" id = "submit" value = "SEND" />
</form>

Note that I added id attributes so we can use document.getElementById. Also, there is no input type "input". It should be text, or you can leave it off. You can add more fields just be adding to the array in the desired order.

Matthew Flaschen
A: 

I'm assuming you mean how do you make a link in the page the form is posted to? Depends on the technology you use. With php it could be

<a href="www.link.com/<?=$_GET['id']?>/<?=$_GET['name']?>">Your link name</a>
controlfreak123
Now that I read your post... it seems like that's probably what he meant. Shrug.
Dutchie432
A: 

If PHP is an option for you, have the form action link to code such as this:

<?php
    if (isset($_GET['id']) && isset($_GET['name'])) {
        header('Location: www.link.com/' . $_GET['id'] . '/' . $_GET['name']);
    }
?>
Andrew67
A: 

Just add an onSubmit event to the form header:

<form action = "" method = "get" name="mylink" onSubmit="return mySend(this);">

And then include the following javascript in your page:

function mySend(frm) {
    window.location="http://www.link.com/"+frm.id.value+"/"+frm.name.value;
    return false;
}

Line 1 sets the new window location (picking up the values from the form-ID input, and the form-NAME input. Line 2 prevents the form from submitting - although you have no action, you don't want this to post anywhere.

Rudu
A: 

Firstly, I would update your field names. Naming an item "name" is never a great idea. Also, add an id to your form.

<form action = "javscript:void();" method = "get"  id = "mainForm">
    <input type = "input" name = "itemId" value = "3" />
    <input type = "input" name = "itemName" value = "gloris" />
    <input type = "submit" class = "button_big" name = "submit" value = "SEND" />
</form>
<button onclick="updateLocation();">Submit</button>

Then just make a javascript function like so.

<script><!--
     function updateLocation(){
        var formObject=document.getElementById('formObject');
        var i = formObject.itemId.value;
        var n = formObject.itemName.value;
        var url = 'www.link.com/' + i + '/' + n;
        window.location=url;
    }
--></script>
Dutchie432