www.webdeveloper.com
Results 1 to 5 of 5

Thread: GetElementsByName with multi-criteria values?

  1. #1
    Join Date
    Feb 2011
    Posts
    24

    GetElementsByName with multi-criteria values?

    Hello
    I am trying to adapt an existing script which returns a list of URLS from my website based on an entry in a search box.

    I would like to adapt it so that I can enter a value other than the string value "xxx" but so that I can search for "xxx" or "yyy".

    I can see that the script uses the function GetElementsByName with a Name value. Is there any way that I can change the value of the Name to be '"xxx" or "yyy"' instead of just "xxx" or should I be using a different function?

    Thank you in advance for your help and advice

  2. #2
    Join Date
    Sep 2011
    Location
    Memphis, TN
    Posts
    5
    yeah you use the || operator. post the code so we can give you better advice

  3. #3
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266
    Both method can be usefull : document.getElementByNames() or document.getElementByTagNames(). See the examples on the links.

  4. #4
    Join Date
    Feb 2011
    Posts
    24
    Quote Originally Posted by andrewbriggs View Post
    yeah you use the || operator. post the code so we can give you better advice
    Thank you for replying so quickly. Sorry the code is huge so I've tried to cut outall the content of the arrays but here it is :
    Code:
    STR_SEARCH_QUERY_MSG="Search results for";STR_NO_RESULT="No results found";STR_SCORE="Score";STR_TERMS="Terms";STR_SEARCH_SIZE="40";MIN_WORD_LEN=0;DISPLAY_SRCH_INFO=1;USE_UTF8=1;REMOVE_ACCENTS=1;BOLD_LINKS=1;ONLINE_WEBSITE=1;ALLWORDSONLY=1;namesArray=new Array(" turkey holiday experts  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ");urlsArray=new Array("../home/index.html","../cappadocia/index.html","../istanbul/index.html","../blacksea/index.html","../pamukkale/index.html","../dailydeparture/index.html","../turkeypackages/index.html","../mini-packages/index.html","../privateluxury/index.html","../specialinterest/index.html","../tailor-madetours/index.html"...)titlesArray=new Array("Turkey Holiday Experts","Turkey Holiday Experts - Cappadocia Tours","Turkey Holiday Experts - Istanbul City Tours",.....)descArray=new Array("","","","","","","","","","","","Class A TURSAB licenced company. Istanbul Tours, Cappadocia Tours, Ephesus and Pamukkale Tours, Private Luxury Tours, Secure payment system","",.......sublinksArray=new Array(194);var linksCount=194;function SubmitSearch(n){var p=document.getElementsByName("jse_query");var idx=n;if(p<0)return false;if(p&&p[idx]&&p[idx].value!=""){if((p[idx].value).replace(/^\s+|\s+$/g,'')!=""){p=document.getElementsByName("jse_form");if(p&&p[idx])p[idx].submit();return true;}}return false;}function switchSearchLang(lang,emptycart){var params="";var currURL=document.location.href;var newURL=(currURL.lastIndexOf('_frame/search2')>=0)?"search2":"search";if(lang!="")newURL+="-"+lang;newURL+=".html";var paramIndex=currURL.lastIndexOf('?');if(paramIndex>-1)newURL+="?"+currURL.substr(paramIndex+1);if(emptycart&&typeof(CleanShopcart)!="undefined")CleanShopcart();document.location.href=newURL;return false;}function getParam(paramName){paramStr=document.location.search;if(paramStr=="")return"";if(paramStr.charAt(0)=="?")paramStr=paramStr.substr(1);arg=(paramStr.split("&"));for(i=0;i<arg.length;i++){arg_values=arg[i].split("=");if(unescape(arg_values[0])==paramName){if(USE_UTF8==1&&self.decodeURIComponent)ret=decodeURIComponent(arg_values[1]);else ret=unescape(arg_values[1]);return ret;}}return"";}function getQueryParam(){var query=getParam("jse_query");query=query.replace(/[\++]/g," ");query=query.replace(/\</g,"&lt;");query=query.replace(/[\"+]/g," ");return query;}function replaceAll(str,from,to){var idx=str.indexOf(from);while(idx>-1){str=str.replace(from,to);idx=str.indexOf(from);}return str;}function formatChars(str){str=str.toLowerCase();if(REMOVE_ACCENTS){var a="*áâãäåòóôõöèéêëçì*îïùúûüÿñ";var b="aaaaaaoooooeeeeciiiiuuuuyn";for(i=0;i<a.length;i++)str=replaceAll(str,a.charAt(i),b.charAt(i));}str=replaceAll(str,"'"," ");return str;}function SortCompare(a,b){if(a[2]==b[2]){if(a[1]<b[1])return 1;else if(a[1]>b[1])return-1;else return 0;}else if(a[2]<b[2])return 1;else return-1;}function jseSearch(internal){var rootURL='';var SelfURL=document.location.href;var paramIndex=SelfURL.indexOf("?");if(paramIndex>-1)SelfURL=SelfURL.substr(0,paramIndex);paramIndex=SelfURL.indexOf("#");if(paramIndex>-1)SelfURL=SelfURL.substr(0,paramIndex);if(ONLINE_WEBSITE){paramIndex=SelfURL.lastIndexOf('/');if(paramIndex>-1){rootURL=SelfURL.substr(0,paramIndex);paramIndex=rootURL.lastIndexOf('/');if(paramIndex>-1){rootURL=SelfURL.substr(0,paramIndex+1);}else rootURL='';}}SelfURL=SelfURL.replace(/\</g,"&lt;");SelfURL=SelfURL.replace(/\"/g,"&quot;");var query=getQueryParam();var lnktarget="";if(internal==1){lnktarget="\" target=\"_blank";}query=formatChars(query);if(query.length==0)return;var found=0,t=0,k=0,score=0,subscore=0,i=0;var keyword="",tmp="";var searchWords=new Array();searchWords=query.split(" ");if(internal==null||internal!=1){document.writeln("<span class='wg-paragraph'>"+STR_SEARCH_QUERY_MSG+" : <strong>"+query+"</span></strong><br>");}res_table=new Array(linksCount);for(t=0;t<linksCount;t++){res_table[t]=new Array(4);res_table[t][0]=0;res_table[t][1]=0;res_table[t][2]=0;res_table[t][3]="";}var significantwords=0;for(i=0;i<searchWords.length;i++){keyword=searchWords[i];if(keyword.length>MIN_WORD_LEN){significantwords++;for(var q=0;q<linksCount;q++){t=q;score=0;tmp=formatChars(descArray[t]);if(tmp.indexOf(keyword)!=-1)score++;if(tmp.indexOf(' '+keyword+' ')!=-1)score+=2;tmp=formatChars(titlesArray[t]);if(tmp.indexOf(keyword)!=-1)score++;if(tmp.indexOf(' '+keyword+' ')!=-1)score+=2;if(namesArray[t].indexOf(keyword)!=-1)score++;if(namesArray[t].indexOf(' '+keyword+' ')!=-1)score+=2;k=q+1;while(k<=linksCount){tmp=descArray[k];if(tmp==null||tmp.charAt(0)!='&')break;subscore=0;tmp=formatChars(descArray[k]);if(tmp.indexOf(keyword)!=-1)subscore++;if(tmp.indexOf(' '+keyword+' ')!=-1)subscore+=2;tmp=formatChars(titlesArray[k]);if(tmp.indexOf(keyword)!=-1)subscore++;if(tmp.indexOf(' '+keyword+' ')!=-1)subscore+=2;if(namesArray[k].indexOf(keyword)!=-1)subscore++;if(namesArray[k].indexOf(' '+keyword+' ')!=-1)subscore+=2;if(subscore>0){var idx=urlsArray[t].indexOf('@');if(idx>0){var lnk=urlsArray[k].substr(0,idx);if(res_table[t][3].indexOf(lnk)==-1)res_table[t][3]+="<tr><td width='35'>&nbsp;</td><td><a href=\""+urlsArray[k].substr(idx+1)+"\" name=\""+lnk+"\">"+titlesArray[k]+"</a></td></tr>";}else if(res_table[t][3].indexOf("\""+urlsArray[k]+"\"")==-1)res_table[t][3]+="<tr><td width='35'>&nbsp;</td><td><a href=\""+urlsArray[k]+lnktarget+"\">"+titlesArray[k]+"</a></td></tr>";score+=subscore;}k++;}q=k-1;if(score>0){res_table[t][0]=t;res_table[t][1]+=score;res_table[t][2]++;found++;}}}}if(found==0){document.write("<p class='wg-paragraph'><b>"+STR_NO_RESULT+"</b></p>");}else {res_table.sort(SortCompare);document.writeln('<div class="wg-paragraph">');for(q=0;q<found;q++)if(res_table[q][1]>0)if(!ALLWORDSONLY||(ALLWORDSONLY&&res_table[q][2]==significantwords)){t=res_table[q][0];var lnk=urlsArray[t]+lnktarget;var idx=urlsArray[t].indexOf('@');if(idx>0)lnk=urlsArray[t].substr(idx+1);if(BOLD_LINKS){document.writeln("<br><b>"+(q+1)+". <a href=\""+lnk+"\">"+titlesArray[t]+"</a></b>");}else document.writeln("<br><b>"+(q+1)+".</b> <a href=\""+lnk+"\">"+titlesArray[t]+"</a>");if(descArray[t].length>2)document.writeln("<br>"+descArray[t]);if(DISPLAY_SRCH_INFO){document.write("<br><span style='font-size: 80%; font-style: italic;'>");if(!ALLWORDSONLY)document.write(""+STR_TERMS+": "+res_table[q][2]+" - ");document.write(""+STR_SCORE+": "+res_table[q][1]);if(urlsArray[t].indexOf('@')>0){document.writeln(" - URL: 'TOWeb demonstration'</span>");}else if(ONLINE_WEBSITE){document.writeln(" - URL: "+rootURL+urlsArray[t].substr(3)+"</span>");}else document.writeln(" - URL: "+urlsArray[t]+"</span>");}if(res_table[q][3].length>0){document.writeln('<table class="wg-paragraph">'+res_table[q][3]+'</table>');}else document.writeln("<br>");}document.writeln('</div>');}document.writeln("<br>");}
    What I want to do is to create a form with a drop down box with options :
    - less than one week
    - one week
    - two weeks
    - more than two weeks
    and then for example if they choose less than one week to display all the tours for 1 day, 2 days, 3, 4, 5 and 6 days.
    Thank you again for your help

  5. #5
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    You should to that to the server-side level. Let's say that you have a search box with the HTML name="search", and you send a query to the server-side application. That server-side application should handle the query. If PHP, the code could be, simplified, as:
    Code:
    $keys=&$_GET;
    if(isset($keys['search'])){
    $search=$keys['search'];
    if($search=="xxx"||$search=="yyy"){
    /* do something */
    }
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles