0

I have a textbox in index.html and I want get the value of it and put it to textbox in another html file which is result.html. (they have the same .js file using)

index.html textbox:

<input id="txt2" readonly="true" type="number" value="0" name="score" style="border:none;background-color:#f0f2f7">

result.html textbox:

<input id="txt3" readonly="true" type="number" value="0" name="score" style="border:none;background-color:#f0f2f7"></td>

this is the code where it will automatically go to the other page:

if((mins == 0) && (secs == 0)) {
    //window.alert("Time is up.Your score is "+score); // change timeout message as required
    document.getElementById('txt2').value = score;
    window.location = "score.html" // redirects to specified page once timer ends and ok button is pressed
} 
else {
    cd = setTimeout("redo()",1000);
}

And how will txt3 get the value of txt2 since they are in different html?

Thanks in advance.

3
  • 1
    If you have no serverside help with passing this value across you might want to try using cookies to make the data persistent across pages. Commented Jan 19, 2013 at 12:27
  • or research on html5 capabilities. I think there was something like local storage. It might be what you are searching for, might be also totally out of line... Commented Jan 19, 2013 at 12:39
  • @MAXIMUM Please consider green-checking answer if answer served your purpose.More details here on how to do so meta.stackexchange.com/questions/23138/… Commented Feb 7, 2013 at 10:58

2 Answers 2

1

Use query string Like this

http://mysite.com/index.html?name=john

and get this name on different html page by using javascript

function loadPageVar (sVar) {  
  return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(sVar).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));  
}  

// Would alert the value of QueryString-variable called name  
alert(loadPageVar("name")); 
Sign up to request clarification or add additional context in comments.

Comments

1

Change result page URL as follows;

window.location = "result.html?val="+document.getElementById('txt2').value;  

result.html

<input id="txt3" readonly="true" type="number" value="0" name="score" style="border:none;background-color:#f0f2f7"></td>  


<script>
document.getElementById('txt3').value=window.location.search.replace("?val=","");
</script>

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.