Forum Moderators: open

Message Too Old, No Replies

Type casting in javascript.

'px'2integer...

         

paolodina

1:09 pm on May 31, 2004 (gmt 0)

10+ Year Member



Dear all,
i'm experiencing a silly problem and for sure a little help would be highly appreciated!

I need a link that allows users to increment the height of an iframe named 'webmailId'. This is the way I accomplish this task:

<a onclick="document.getElementById('webmailId').style.height+=100;">+100</a>

The fact is that the result of document.getElementById('webmailId').style.height is a string, '200px', to which i can't add an integer value!
Do you have a solution?

And another thing.. is there a way to hold the user's setting through the pages?

TIA,
Paolo

Rambo Tribble

1:43 pm on May 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var x="800px";
var y=x.split("p");
var z=Number(y[0]);
alert(x + " " +z);
</script>
</head>
<body>
</body>
</html>

Variables and state information is normally passed between pages with cookies.

[edited by: Rambo_Tribble at 1:44 pm (utc) on May 31, 2004]

Alternative Future

1:44 pm on May 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi paolodina,

Would this not work for you? By changing the style class, you can get the desired effect (I think!).

<style>
.yourNewStyleRules{
height:250px
}
.myOldRules{
height:50px
}
</style>

<a onclick="document.getElementById('webmailId').className='yourNewStyleRules';">+100</a>

HTH,

-George

paolodina

2:38 pm on May 31, 2004 (gmt 0)

10+ Year Member



Wonderful, 'split' does a great job ;-)

Thanks,
Paolo.