Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function copy

Status
Not open for further replies.

ro6er

Programmer
Jul 1, 2003
76
Hi, this is definitely an easy one, it's just I don't use javascript much. I've trying to get the copy function to work so when someone fills in the form it redirects with the data in the url eg?test=whatever the data is. At the moment it does this: ?test=%20+%20copythis2%20+


Code:
<html>
<head>
<script type="text/javascript">
<!--
   function copy()
   {
document.one.copythis2.value  = document.one.copythis.value 
}
function confirmation() {
	//var answer = confirm("Are you sure you want to update quantity")
//	if (answer){

		window.location = "?test= + copythis2 + ";
//	}
//	else{
		
	//}
}
//-->
</script>
</head>
<body>
<form name="one">
<input type="input" name="copythis" onchange="confirmation()" value="">
</form>
</body>
</html>
 
Hi
[ul]
[li]Why are you trying to involve the copy() function into this ? Is pointless to perform that assignment and dispose the document immediately after.[/li]
[li]If you want to redirect and send the value entered in the [tt]form[/tt], then why not just submit the [tt]form[/tt] ?[/li]
[/ul]
HTML:
[b]<html>[/b]
[b]<head>[/b]
[b]</head>[/b]
[b]<body>[/b]
[b]<form[/b] [maroon]action[/maroon][teal]=[/teal][green][i]""[/i][/green][b]>[/b]
[b]<input[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"input"[/i][/green] [maroon]name[/maroon][teal]=[/teal][green][i]"copythis"[/i][/green] [maroon]onchange[/maroon][teal]=[/teal][green][i]"this.form.submit()"[/i][/green] [maroon]value[/maroon][teal]=[/teal][green][i]""[/i][/green][b]>[/b]
[b]</form>[/b]
[b]</body>[/b]
[b]</html>[/b]

Feherke.
 
Because it's within another form
 
Why not just set the forms action to GET and submit the form normally. You can still control whether its submitted or not with JS depending on what the answer is from the confirm box.
Code:
<script>

function confirmation() {
    //var answer = confirm("Are you sure you want to update quantity")
//    if (answer){

[red]        return true;[/red]
//    }
//    else{
        [red]return false;[/red]
    //}
}
</script>

<form name="one" [red]method="GET"[/red] [blue]action="pagetosendthisto.html"[/blue] [green]onSubmit="[blue]return confirmation();[/blue]"[/green]>
<input type="input" name="copythis" value="">
</form>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Oh never mind then missed that part.

In that case then you can add the value to the redirection page.

but you need to give the location an actual address.


Code:
 window.location = "[green]thispage.xxx[/green]?test=" + copythis2;

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I don't want to do that as there's going to be another form wrapped around it. Which handles loads of varibles. All I want to do is generate a url.
 
See my second answer, while completely ignoring the first one. Sorry about that.

Except you'll probably need t either pass the copy this value to your confirmation function or just directly use the value from the form in your confirmation function.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks vacunita but that doesn't seem to work:

Code:
<html>
<head>
<script type="text/javascript">
<!--
   function copy()
   {
document.one.copythis2.value  = document.one.copythis.value 
}
function confirmation() {


window.location = "thispage.xxx?test=" + copythis2;
		
}
//-->
</script>
</head>
<body>
<form name="one">
<input type="input" name="copythis" onchange="confirmation()" value="">
</form>
</body>
</html>
 
1. Your confirm function has no idea what your copy function is doing at the same time your copy function is not being called at all. Additionally there is no copythis2 object inside the 'one' form so you really are not referencing anything.

2. your passing an object to your location url instead of the value it has

so:

Code:
<html>
<head>
<script type="text/javascript">
<!--
function confirmation() {

var copythis2= document.one.copythis.value;
window.location = "pagetoredorectto.xxx?test=" + copythis2;
        
}
//-->
</script>
</head>
<body>
<form name="one">
<input type="input" name="copythis" onchange="confirmation()" value="">
</form>
</body>
</html>

Additionally I hope you don't expect my usage of 'thispage.xxx' to work. You need to replace that with the address of the page you are redirecting to.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
That's what I was missing thankyou :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top