Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Calling 2 pages with the condition of selecting radiobutton.
Old 01-29-2010, 01:14 AM Calling 2 pages with the condition of selecting radiobutton.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Hi.....

I want to run a function who calls 2 different pages as per the selection of radio button........

for example.............I want 2 searches

1. Based on keywords
2. Based on Company name

Please let me know how can I do this...........thanks...
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-29-2010, 04:36 AM Re: Calling 2 pages with the condition of selecting radiobutton.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
with javascript
HTML Code:
<script type="text/javascript">
function doSearch(){
  if(document.getElementById('inpRad1').checked){
    //change the action value of the first <form>
    document.getElementsByTagName('form')[0].action="/searchKeywords.php";
  }
  else{
     document.getElementsByTagName('form')[0].action="/searchName.php";
  }
  //submit the form
  document.getElementsByTagName('form')[0].submit();
}
</script>
<form name="frm" action="#">
  <input type="radio" id="inpRad1" name="searchType">keywords<br/>
  <input type="radio" id="inpRad2" name="searchType">name<br/>
  <input type="button" value="go" onclick="javascript:doSearch();"/>
</form>
Not tested, and written from memory, but should do the trick.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 01-29-2010 at 04:39 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 01-29-2010, 06:06 AM Re: Calling 2 pages with the condition of selecting radiobutton.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Thanks a ton!!....

I'll try and let you know.....
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 01-30-2010, 12:59 AM Re: Calling 2 pages with the condition of selecting radiobutton.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Quote:
Originally Posted by tripy View Post
with javascript
HTML Code:
<script type="text/javascript">
function doSearch(){
  if(document.getElementById('inpRad1').checked){
    //change the action value of the first <form>
    document.getElementsByTagName('form')[0].action="/searchKeywords.php";
  }
  else{
     document.getElementsByTagName('form')[0].action="/searchName.php";
  }
  //submit the form
  document.getElementsByTagName('form')[0].submit();
}
</script>
<form name="frm" action="#">
  <input type="radio" id="inpRad1" name="searchType">keywords<br/>
  <input type="radio" id="inpRad2" name="searchType">name<br/>
  <input type="button" value="go" onclick="javascript:doSearch();"/>
</form>
Not tested, and written from memory, but should do the trick.
Hey tripy,

Its not working..............please advice.....
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 01-31-2010, 06:47 AM Re: Calling 2 pages with the condition of selecting radiobutton.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Okay, I just tested it, and it works.
What is the reported error then ?
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-03-2010, 12:26 AM Re: Calling 2 pages with the condition of selecting radiobutton.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Quote:
Originally Posted by tripy View Post
Okay, I just tested it, and it works.
What is the reported error then ?
Thanks.............actually............there was no error..............that's the problem......it didn't work.............well.............I am merging these 2 function....

PHP Code:
function valid_search(frm)
{
    if(
frm.city_search.value==""||frm.city_search.value=="Select City")
    {
    
alert("Please select city first!");
    
frm.city_search.focus();
    return 
false;
    }
    
   if(
frm.get_searchword.value=="")
    {
    
alert("Please enter category / company name for search.");
    
frm.get_searchword.focus();
    return 
false;
    }
    return 
true;
}


function 
doSearch()
{
  if(
document.getElementById('company').checked){
    
//change the action value of the first <form>
    
document.getElementsByTagName('form')[0].action="/searchName.php";
  }
  else{
     
document.getElementsByTagName('form')[0].action="/"searchKeywords.php;
  }
  
//submit the form
  
document.getElementsByTagName('form')[0].submit();

Thanks A lot for your help.....
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes

Last edited by Isabella_Smith; 02-03-2010 at 02:50 AM..
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 02-03-2010, 02:28 AM Re: Calling 2 pages with the condition of selecting radiobutton.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
What browser are you using, and can you please post the complete page code ?
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-03-2010, 02:48 AM Re: Calling 2 pages with the condition of selecting radiobutton.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
browser: Mozilla Firefox

Code is here:
Quote:
<form action="srch/searchkey.php" method="POST" name="frm" id="frm" onSubmit="return valid_search(this);">
<div id="divSearbar" class="search_bar" style="height:78px;">
<div id="divCity" class="search_element">
<div class="search_label"><b>City:</b></div>
<div class="clear"></div>
<div >
<select name="city_search" id="city_search" class="input_city">
<option value="">Select City</option>
<?
$city_se="select * from tblcity order by city asc";
$result_se=mysql_query($city_se);
while($row_se=mysql_fetch_array($result_se))
{
?>
<option value="<?=$row_se['city']?>" <? if($row_se['city']==$row['city']) echo "selected" ?>>
<?=$row_se['city']?>
</option>
<?
}
?>
</select>
</div>
</div>
<div class="search_element">
<div id="cat_comp" class="search_label display"><b>Search By</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;
<input type="radio" name="comp_cat" class="radiobtn" id="company" />
Company / Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;
<input type="radio" name="comp_cat" class="radiobtn" id="category" checked="true" tabindex="1" />
Product / Services </div>
<div id="comp" class="search_label hidden"> <b>Search By</b> &nbsp; Company / Name </div>
<div class="clear"></div>
<input id="get_searchword" name="get_searchword" class="input_search" value="" />
<div class="clear"></div>
</div>
<div class="search_element">
<div id="divAreaLabl" class="search_label"><b>Which part of ?</b></div>
<div class="clear"></div>
<div id="divAreaVal">
<input id="get_val" class="input_area">
</div>
<div class="clear"></div>
<div id="area_part_main" class="search_label" style="overflow:hidden;height:30px;text-align:left;"></div>
</div>
<div style="float:left; padding-left:6px; padding-top:8px;">
<input type="submit" class="Gobtn" value="Go"/>
</div>
</div>
</form>
Please let me know if you need anything else.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes

Last edited by Isabella_Smith; 02-03-2010 at 02:50 AM..
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 02-03-2010, 04:16 AM Re: Calling 2 pages with the condition of selecting radiobutton.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
drop the form onSubmit event, and replace the <submit> button with a regular button that does the call to the javascript function.

Without the valid_search js function, I cannot say where this comes, but mostly, as the valid_search returns true, the form is submitted without checking which destination it should go to because the submit button override it.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-03-2010, 05:24 AM Re: Calling 2 pages with the condition of selecting radiobutton.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
I think it won't work as I've already tried to call it on submit button but didn't work.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 02-03-2010, 05:47 AM Re: Calling 2 pages with the condition of selecting radiobutton.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
I think it won't work as I've already tried to call it on submit button but didn't work.
And that's the point of not having a submit button.
Replace the <input type="submit"> with an <input type="button" onclick="javascript:myFunction()">, and remove the onSubmit="return valid_search(this);" on the form element.

You have to use a custom made submit, and cannot rely on the automatic one.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-08-2010, 12:42 AM Re: Calling 2 pages with the condition of selecting radiobutton.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Quote:
Originally Posted by tripy View Post
And that's the point of not having a submit button.
Replace the <input type="submit"> with an <input type="button" onclick="javascript:myFunction()">, and remove the onSubmit="return valid_search(this);" on the form element.

You have to use a custom made submit, and cannot rely on the automatic one.
Hi Tripy,

Sorry for replying so late.

Here's the changes I've made as per your suggestions.

But it doesn't seems to be working.

PHP Code:
<form action="srch/searchkey.php?id="$_POST['get_searchword']"&title="$_POST['city_search']"" method="POST" name="frm" id="frm">
            <div id="divSearbar" class="search_bar" style="height:78px;">
              <div id="divCity" class="search_element">
                <div class="search_label"><b>City:</b></div>
                <div class="clear"></div>
                <div >
                  <select name="city_search" id="city_search" class="input_city">
                    <option value="">Select City</option>
                    <?
                                $city_se
="select * from tblcity order by city asc";
                                
$result_se=mysql_query($city_se);
                                while(
$row_se=mysql_fetch_array($result_se))
                                {
                                
?>
                    <option value="<?=$row_se['city']?><? if($row_se['city']==$row['city']) echo "selected" ?>>
                    <?=$row_se['city']?>
                    </option>
                    <?
                                
}
                                
?>
                  </select>
                </div>
              </div>
              <div class="search_element">
                <div id="cat_comp" class="search_label display"><b>Search By</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="radio" name="comp_cat" class="radiobtn" id="company" />
                  Company / Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <input type="radio" name="comp_cat" class="radiobtn" id="category" checked="true" tabindex="1" />
                  Product / Services </div>
                <div id="comp" class="search_label hidden"> <b>Search By</b> &nbsp; Company / Name </div>
                <div class="clear"></div>
                <input id="get_searchword" name="get_searchword" class="input_search" value="" />
                <div class="clear"></div>
              </div>
              <div class="search_element">
                <div id="divAreaLabl" class="search_label"><b>Which part of ?</b></div>
                <div class="clear"></div>
                <div id="divAreaVal">
                  <input id="get_val" class="input_area">
                </div>
                <div class="clear"></div>
                <div id="area_part_main" class="search_label" style="overflow:hidden;height:30px;text-align:left;"></div>
              </div>
              <div style="float:left; padding-left:6px; padding-top:8px;">
                <input type="button" class="Gobtn" value="Go" onClick="javascript:doSearch()"/>
              </div>
            </div>
          </form>
Looking forward to you............thanks.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 02-08-2010, 02:03 AM Re: Calling 2 pages with the condition of selecting radiobutton.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Ok, got it working with:
HTML Code:
<html>
    <script type="text/javascript">
    function doSearch(){
        doSub=true;
        if(document.getElementById('company').checked){
            //change the action value of the first <form>
            document.getElementsByTagName('form')[0].action="/searchName.php";
            if(document.getElementById('city_search').selectedIndex==0){
                alert("Please select city first!");
                document.getElementById('city_search').focus();
                doSub=false;
            }
        }
        else{
            document.getElementsByTagName('form')[0].action="/searchKeywords.php";
            if(document.getElementById('get_searchword').value==""){
                alert("Please enter category / company name for search.");
                document.getElementById('get_searchword').focus();
                doSub=false;
            }
        }
        //submit the form
        if(doSub===true){
            document.getElementsByTagName('form')[0].submit();
        }
    }  
    </script>
    <body>
        <form action="srch/searchkey.php?id="$_POST['get_searchword']"&title="$_POST['city_search']"" method="POST" name="frm" id="frm">
            <div id="divSearbar" class="search_bar" style="height:78px;">
              <div id="divCity" class="search_element">
                <div class="search_label"><b>City:</b></div>
                <div class="clear"></div>
                <div >
                  <select name="city_search" id="city_search" class="input_city">
                    <option value="">Select City</option>
                    <option value="1">City 1</option>
                    <option value="2">City 2</option>
                    <option value="3">City 3</option>
                    <option value="4">City 4</option>
                    <option value="5">City 5</option>
                  </select>
                </div>
              </div>
              <div class="search_element">
                <div id="cat_comp" class="search_label display"><b>Search By</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="radio" name="comp_cat" class="radiobtn" id="company" />
                  Company / Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <input type="radio" name="comp_cat" class="radiobtn" id="category" checked="true" tabindex="1" />
                  Product / Services </div>
                <div id="comp" class="search_label hidden"> <b>Search By</b> &nbsp; Company / Name </div>
                <div class="clear"></div>
                <input id="get_searchword" name="get_searchword" class="input_search" value="" />
                <div class="clear"></div>
              </div>
              <div class="search_element">
                <div id="divAreaLabl" class="search_label"><b>Which part of ?</b></div>
                <div class="clear"></div>
                <div id="divAreaVal">
                  <input id="get_val" class="input_area">
                </div>
                <div class="clear"></div>
                <div id="area_part_main" class="search_label" style="overflow:hidden;height:30px;text-align:left;"></div>
              </div>
              <div style="float:left; padding-left:6px; padding-top:8px;">
                <input type="button" class="Gobtn" value="Go" onClick="javascript:doSearch()"/>
              </div>
            </div>
          </form>
    </body>
</html>
You had a spelling error in doSearch:
HTML Code:
document.getElementsByTagName('form')[0].action="/"searchKeywords.php;
should have been
HTML Code:
document.getElementsByTagName('form')[0].action="/searchKeywords.php";
This was rendering the whole function invalid, and thus was ignored by the browser.
Furthermore, I have integrated the check in the doSearch(), no reason to keep them separated, and I rewrote them to use the DOM methods to access the elements.
The formname.fieldname way is deprecated.

By the way, in the case of a drop down, you cannot use the dropdown.value way of an input filed to get the value.
You must use:
Code:
dd=document.getElementById('mySelectId');
value=dd.options[dd.selectedIndex].value
a select having an array of options, you have to point to the value of that option based on the selected index position of the drop down.
The dropdown.value method works only in internet explorer, as far as I know.

May I ask with what browser do you tested it ?
If you didn't use firefox, you should.
Add the firebug extension, and you would have seen every errors pointed to the right line, as for every warning about deprecated javascript calls.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-08-2010, 02:13 AM Re: Calling 2 pages with the condition of selecting radiobutton.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Thanks a ton!!! tripy,

I am testing it in Firefox.

I'll try this and let you know the results.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes

Last edited by Isabella_Smith; 02-08-2010 at 02:25 AM..
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 02-08-2010, 02:56 AM Re: Calling 2 pages with the condition of selecting radiobutton.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Thanks tripy,

Its working perfectly...................................Your are a STAR!!!!

Thanks a lot.
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 02-08-2010, 04:57 AM Re: Calling 2 pages with the condition of selecting radiobutton.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
.....
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes

Last edited by Isabella_Smith; 02-08-2010 at 05:07 AM..
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 02-08-2010, 08:37 AM Re: Calling 2 pages with the condition of selecting radiobutton.
Junior Talker

Posts: 1
Name: eliza sahoo
Trades: 0
If we are using ASP.NET Radiobuttonlist in our page it becomes a little difficult to find the instance of it through Javascript because it is rendered in a different way in the browser ( the code is reproduced below )

ASP.net Code
-----------------
Code:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatLayout="Table">
<asp:ListItem Text="AAA"></asp:ListItem>
<asp:ListItem Text="BBB"></asp:ListItem>
</asp:RadioButtonList>

Is rendered in browser as :

<table id="RadioButtonList1" border="0">
<tr>
<td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="AAA" /><label for="RadioButtonList1_0">AAA</label></td>
</tr>
<tr>
<td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="BBB" /><label for="RadioButtonList1_1">BBB</label></td>
</tr>
</table>
<link drop removed>
__________________
Cheers,

Please login or register to view this content. Registration is FREE

Last edited by chrishirst; 02-08-2010 at 05:13 PM..
elizas is offline
Reply With Quote
View Public Profile Visit elizas's homepage!
 
Reply     « Reply to Calling 2 pages with the condition of selecting radiobutton.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.85915 seconds with 12 queries