Page 1 of 1

Window Manipulation

Posted: Thu Oct 07, 2004 11:12 am
by sell-traffic
Hi,

I'm trying to open a new window, and fill in 2 fields. I can't show you my exact problem, but I've created another example and have the same problem.

The window opens fine, but the fields are not filled in, and I think part of the problem is that the form doesn't have a name, and I don't have control over the file to give it one.

This is the form I am trying to fill in...

Code: Select all

<form method="post" action="loginurlhere">
                          <table  align=center width="100" border="0" cellspacing="2" cellpadding="0">
                            <tr> 
                              <td width="129">UserName:</td>
                              <td width="371">Password:</td>
                            </tr>
                            <tr> 
                              <td width="129"> 
                                <input type="text" name="username" size="12" maxlength="12" />
                              </td>
                              <td width="371"> 
                                <input type="password" name="password" size="12" maxlength="12" />
                              </td>
                            </tr>
                            <tr> 
                              <td width="129"> 
                                <div align="right"> 
                                  <input type="reset" name="Reset" value="Reset"  class="button">
                                  &nbsp; &nbsp; </div>
                              </td>
                              <td width="371"> &nbsp; &nbsp; 
                                <input type="submit" name="Submit2" value="Submit"  class="button">
                              </td>
                            </tr>
                            <tr> 
                              <td width="129">&nbsp; </td>
                              <td width="371">&nbsp; </td>
                            </tr>
                          </table>
                     </form>
This is the function I wrote to manipulate it.

Code: Select all

<script language=Javascript> 
function openlogin(user,pass) &#123;
	window.open( 'pageurlhere', 'newwindow', 'top=80,left=60,width=400,height=600' );
	newwindow.document.form.username.value = $user;
	newwindow.document.form.password.value = $pass;
&#125;
</script>
Can someone help me?

Thanks,

Josh

Posted: Thu Oct 07, 2004 11:18 am
by feyd

Code: Select all

newwindow.document.forms&#1111;0].elements&#1111;'username'].value = '$user';
not so sure you can read and write to a password field though.. I haven't tried it in a looong time :)

note that the forms array has numeric and named entries.. so if you named (hint) the form, you can use that more effectively, if your pages have ~unknown numbers of forms.

Posted: Thu Oct 07, 2004 11:20 am
by phpScott
if you only have the one form on the new window that something like

Code: Select all

<script language=Javascript>
function openlogin(user,pass) {
   window.open( 'pageurlhere', 'newwindow', 'top=80,left=60,width=400,height=600' );
   newwindow.document.forms[0].username.value =<?php echo $user; ?>
   newwindow.document.forms[0].password.value = <?php echo $pass; ?>
}
</script>
should work.

The DOM keeps all forms in an array the can be accessed by using the forms[] method.

Posted: Thu Oct 07, 2004 11:39 am
by sell-traffic
Thanks for the replies.

Didn't work I'm afraid. No errors, but the form still doesn't fill in.

Josh

...

Posted: Thu Oct 07, 2004 3:36 pm
by Calimero
Go to this site

http://javascriptkit.com/javatutors/

I found the solution there, and have it on my hard drive (in two pages) - but can't upload.

Search for these keywords (in headings on the pages, I'll try to find it, but if not this is pre-info where to look for.

Posted: Thu Oct 07, 2004 4:26 pm
by feyd
what's the new code that you tried?

Posted: Fri Oct 08, 2004 1:33 pm
by sell-traffic
Here it is...

Code: Select all

<script language=Javascript> 
function openlogin(user,pass) &#123;
	window.open( 'URL', 'newwindow', 'top=80,left=60,width=400,height=600' );
	newwindow.document.forms&#1111;0].username.value = "username";
	newwindow.document.forms&#1111;0].password.value = "pass";
&#125;
</script>

Posted: Fri Oct 08, 2004 2:42 pm
by feyd
try this..

Code: Select all

var newwindow = window.open( ...... )

Posted: Fri Oct 08, 2004 6:37 pm
by sell-traffic
nada, same problem.