Jump to content

update two <div> in one time


avenger108

Recommended Posts

hello everyone,

 

i need some advice...

 

my problem is i want to update two <div> after i click a button...

 

this is the scenario...

i have insert a number '5' and then i click submit button...

once i click the submit button, i want to display :

 

that number '5' in <div id="one"> , and

total amount '5*300' in <div id="second"> ...

 

please help me how to do that...

 

thank you...

 

Link to comment
Share on other sites

This may or may not be what you are looking for, and this probably isn't the best way to do this, but it works...

 

Hope this helped. :)

 

<html>
<body>

	<script type="text/javascript">
		var foo

		function Return(num)
		{
			foo = num;
		}

		function Check()
		{
			document.getElementById("one").innerHTML = foo;
			document.getElementById("second").innerHTML = foo*300;
		}
	</script>

	<input name="number" onkeyup="Return(this.value)" type="textbox" /><br />
	<input type="button" onclick="Check()" value="Click me Now!" /><br /><br />

	Number Entered: <span id="one"></span><br />
	Total Amount: <span id="second"></span><br />
</body>
</html>

Link to comment
Share on other sites

i've try to modify your coding... like this...

 

 

 

<html>
<body>

	<script type="text/javascript">
		var foo


		function Check()
		{
			document.getElementById("one").innerHTML = Check1();
			document.getElementById("second").innerHTML = Check2();
		}
		function Check1()
		{
			foo = encodeURI( document.getElementById("number").value );
		}
		function Check2()
		{
			document.getElementById("second").innerHTML = encodeURI( document.getElementById("number").value )*300;
		}
	</script>

	<input name="number" id="number" type="textbox" /><br />
	<input type="button" onclick="Check()" value="Click me Now!" /><br /><br />

	Number Entered: <span id="one"></span><br />
	Total Amount: <span id="second"></span><br />
</body>
</html>

 

but the answer is like this....

 

Number Entered: undefined

Total Amount: undefined

 

.....can you help me how to solve this....

 

 

Link to comment
Share on other sites

ops...sorry... i've already found the answer...this is my new code...

 

<html>
<body>

	<script type="text/javascript">
		var foo


		function Check()
		{
			document.getElementById("one").innerHTML = Check1();
			document.getElementById("second").innerHTML = Check2();
		}
		function Check1()
		{
			foo = encodeURI( document.getElementById("number").value );
			return foo;
		}
		function Check2()
		{
			foo2 = encodeURI( document.getElementById("number").value )*300;
			return foo2;
		}
	</script>

	<input name="number" id="number" type="textbox" /><br />
	<input type="button" onclick="Check()" value="Click me Now!" /><br /><br />

	Number Entered: <span id="one"></span><br />
	Total Amount: <span id="second"></span><br />
</body>
</html>

 

thank you very much 4 your help bro....

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.