views:

14

answers:

1

This piece of code produces a page with two vertical columns:

<frameset id="set" cols="*,*">
    <frame id="frame1" src="index.html"> 
    <frame id="frame2" src="index2.html"> 
</frameset>  

However, I want to be able to set the cols value independantly like this:

function setvalue(){   
    var framewidth=prompt("Enter the default right column width : ", "50%")
}

and then change the cols value... This is where my problem lies, I can't get the script right... Here's what it looks like:

<Script>
  document.getElementByid["set"].cols.value = framewidth;
</script>

Where am I going wrong?

+1  A: 

There are a few things i see wrong in your code:

the document.getElementById is a function so it should be called like so:

document.getElementById("set");

secondly when you set value for attribute of an element, e.g. "cols" in your case, you should do it like so:

document.getElementById("set").cols = "20%, 80%"

I did a quick test in Firefox and this works:

<html>
<head>
   <script type="text/javascript">
      function setvalue(){   
         var framewidth=prompt("Enter the default right column width : ", "50")

         var width = parseInt(framewidth);
         width = isNaN(width) ? 50 : width;

         var val = (100 - width) + "%, " + width + "%";

         document.getElementById("set").cols = val
      }

      window.onload = setvalue;
   </script>
</head>
<frameset id="set" cols="*,*">
    <frame id="frame1" src="index.html"> 
    <frame id="frame2" src="index2.html"> 
</frameset>
</html>

Set the value in prompt as: 80

naikus