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
https://forums.phpfreaks.com/topic/72058-update-two-in-one-time/
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>

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....

 

 

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....

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.