2

I am trying to pass values between boxes.

So, When a User types inside of the first text box:

<input type="text" placeholder="Your personal message" id="valbox"></input>
<input type="submit" name="design1" id="butval" value="Choose Design"></input>

Then they click the 'choose design' button, and what they typed in, gets passed to another input text box on the same page.

this is the second input box i want to pass it to.

<input type="text" class="input-text" name="billing_last_name" id="billing_last_name" placeholder="" value="">

Any help would be much appreciated thank you

1
  • so what have you done so far? Commented Sep 9, 2013 at 1:00

3 Answers 3

1

Live Demo

Instead of a submit type input use a button type input.

HTML

<input type="text" placeholder="Your personal message" id="valbox"></input>
<input type="button" name="design1" id="butval" value="Choose Design"></input>
<input type="text" class="input-text" name="billing_last_name" id="billing_last_name" placeholder="" value="">

JS

window.onload = function(){
    document.getElementById('butval').onclick = function(){
        document.getElementById('billing_last_name').value = document.getElementById('valbox').value;   
    }
}; 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, this worked great. I had to finish up some code, and my javascript is horrible if you can't tell
0

First add a clicklistener for the submit button and inside that callback pass the text through the elements

document.getElementById("butval").addEventListener("click", function(event){
    var text = document.getElementById("valbox").value;
    document.getElementById("billing_last_name").value = text;
    event.preventDefault();
    return false;
});

Comments

0

this is by far easiest in jquery given

<input type="text" placeholder="Your personal message" id="valbox"></input>
<input type="submit" name="design1" id="butval" value="Choose Design"></input>

<input type="text" class="input-text" name="billing_last_name" id="billing_last_name" placeholder="" value="">

use a simple

$("#butval").click(function(event){
    $("#billing_last_name").html("<p>"+$("#valbox").html()+"</p>");
    event.preventDefault();
});

but better change type="submit" to type="button" then you can remove the essentially unnecessary line event.preventDefault();

Comments

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.