Window Manipulation

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
sell-traffic
Forum Commoner
Posts: 26
Joined: Thu Aug 05, 2004 9:35 pm

Window Manipulation

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
sell-traffic
Forum Commoner
Posts: 26
Joined: Thu Aug 05, 2004 9:35 pm

Post by sell-traffic »

Thanks for the replies.

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

Josh
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what's the new code that you tried?
sell-traffic
Forum Commoner
Posts: 26
Joined: Thu Aug 05, 2004 9:35 pm

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try this..

Code: Select all

var newwindow = window.open( ...... )
sell-traffic
Forum Commoner
Posts: 26
Joined: Thu Aug 05, 2004 9:35 pm

Post by sell-traffic »

nada, same problem.
Post Reply