function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
swamyswamy 

Alert box by script

Hi,This is swamy...am getting small doubt ..just clear it plz....

 

am writing a small v.f ....in that some "validation" is given by script...i.e.,if name ==null ...it shows an error by alert box....but it's not workin...Can you justify this.....

 

Script:

<script type="text/javascript">
var val1=document.getElementById("{!$Component.name_select}").value
alert(val1)

function btn(){
if(document.getElementById('name_select').value=="")
{
alert('Please fill all the data ');
}
}
</script

 

v.f:

 

<apex:inputtext value="{!nameVal}"  id="name_select"/>

 

<apex:commandButton value="INSERT" style="color:red;" action="{!doInsert}" onclick="btn();"/>

tukmoltukmol

use the same: {!$Component.name_select} in the btn function as you did in the first part of the JS you posted

swamyswamy

i didn't understood wat us said....

tukmoltukmol

tukmol wrote:

use the same: {!$Component.name_select} in the btn function as you did in the first part of the JS you posted



swamy wrote:

i didn't understood wat us said....



swamy wrote:

Hi,This is swamy...am getting small doubt ..just clear it plz....

 

am writing a small v.f ....in that some "validation" is given by script...i.e.,if name ==null ...it shows an error by alert box....but it's not workin...Can you justify this.....

 

Script:

<script type="text/javascript">

// here you used $Component.name_select (first part)
var val1=document.getElementById("{!$Component.name_select}").value
alert(val1)

function btn(){
if(document.getElementById('name_select').value=="") //here you used just "name_select"
{
alert('Please fill all the data ');
}
}
</script

 

v.f:

 

<apex:inputtext value="{!nameVal}"  id="name_select"/>

 

<apex:commandButton value="INSERT" style="color:red;" action="{!doInsert}" onclick="btn();"/>


swamyswamy

sorry...it's not working..................

Malika Pathak 9Malika Pathak 9
Hii swamy,

use the below code to check your validation.

Script:
 
<script type="text/javascript">

// here you used $Component.name_select (first part)
var val1=document.getElementById("{!$Component.name_select}").value
alert(val1)

function btn(){
//if(document.getElementById("{!$Component.name_select}").value.length > 0) // check this also if not below line not work
if(document.getElementById('name_select').value.length > 0) //here you used just "name_select"
{
alert('Please fill all the data ');
}
}
</script



v.f:
<apex:inputtext value="{!nameVal}"  id="name_select"/>
<apex:commandButton value="INSERT" style="color:red;" action="{!doInsert}" onclick="btn();"/>
if you find this helpful mark it as the best answer.

thanks 
Malika Pathak.