Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Непонятное завершение функции (https://javascript.ru/forum/misc/43532-neponyatnoe-zavershenie-funkcii.html)

culver 09.12.2013 19:20

Непонятное завершение функции
 
Добрый день, есть код, из функции проверки заполнения полей:
function check_vendor_new_user(){
	var checkboxes = $('.svuf_checkbox');
	var checkbox_checked = 0;
	for (var i in checkboxes) {
		if (checkboxes[i].checked) checkbox_checked = 1;
	}
	var lvalue = document.send_vendor_user_form.logname.value;
	log_checked = check_vendor_user_login(lvalue);
...

почему-то функция завершается, возвращая труе на строчке:
var lvalue = document.send_vendor_user_form.logname.value;

Подскажите пожалуйста, где искать зарытую собаку? :)

cyber 09.12.2013 19:31

culver, у меня плохая новость, строчка
var lvalue = document.send_vendor_user_form.logname.value;

не возвращает значения функции, а создает переменную и устанавливает ей значение

culver 09.12.2013 21:55

Вот именно, я не понимаю почему при пошаговом выполнении функция завершается при переходе на эту строку? Этого не должно быть.
В чём могут быть ещё проблемы?

culver 09.12.2013 22:19

Заменил эту строку на:
var lvalue = $('#login').val();

и глюк пропал.
JQuery это, конечно, прекрасно, но знать чистый JS тоже хочется.
Подскажите пожалуйста что это было?

culver 09.12.2013 23:02

Вот функция, теперь такой глюк выскакивает на последнем ифе.
function check_vendor_new_user(){
	var checkboxes = $('.svuf_checkbox');
	var checkbox_checked = 0;
	for (var i in checkboxes) {
		if (checkboxes[i].checked) checkbox_checked = 1;
	}
	var lvalue = $('#login').val();
	log_checked = check_vendor_user_login(lvalue);
	if (!log_checked) {
		alert('Please, choose another login.');
		return false;	
	}
if( document.send_vendor_user_form.company.value &&
	document.send_vendor_user_form.home_page.value &&
	(document.send_vendor_user_form.radioSet[0].checked || document.send_vendor_user_form.radioSet[1].checked || document.send_vendor_user_form.radioSet[2].checked) &&
	document.send_vendor_user_form.position.value &&
	document.send_vendor_user_form.name.value &&
	document.send_vendor_user_form.second_name.value &&
	document.send_vendor_user_form.email.value &&
	document.send_vendor_user_form.phone1.value &&
	document.send_vendor_user_form.phone2.value &&
	document.send_vendor_user_form.country.value &&
	document.send_vendor_user_form.state.value &&
	document.send_vendor_user_form.city.value &&
	document.send_vendor_user_form.zip.value &&
	document.send_vendor_user_form.adres.value &&
	document.send_vendor_user_form.pas.value &&
	checkbox_checked){
	return true;
	} else {
	alert('Please fill all * fields correctly.');
	return false;
	}
}

culver 09.12.2013 23:18

Может ли проблема быть в коде страницы или в других скриптах, которые используются на этой странице? Где нужно искать перехват? Как функция может завершаться при сравнении значений элементов?

culver 09.12.2013 23:41

Ну в первом случае return не стояло, а во втором случае (в последнем ифе) завершается при наличии пустых полей. Поэтому мне и кажется, что завершается при обращении к элементу, что есть бредом, но другого объяснения я не вижу.

culver 09.12.2013 23:57

выполняю функцию пошагово с помощью Firebug в firefox, а так как форма отправляется на сервер, то функция возвращает true.
<form style="padding:0px;margin:0px;" method="post" name="send_vendor_user_form" onsubmit="return check_vendor_new_user();" action="./vendor_edit_user.php">

culver 10.12.2013 00:01

Если вставляю alert в последнем ифе перед return true, то до его выполнения функция не доходит.

culver 10.12.2013 00:13

до проверки ифа. Сейчас в Опере проверяю - та же картина.

culver 10.12.2013 00:20

Странное дело, в Firebug провожу мышкой над строкой
document.send_vendor_user_form.company.value
и при проведении над словом company выскакивает подсказка "undefined".
Хотя в форме такое поле есть:
<form style="padding:0px;margin:0px;" method="post" name="send_vendor_user_form" onsubmit="return check_vendor_new_user();" action="./vendor_edit_user.php">
<input type="Hidden" name="product_id" value="{$product}">
<input type="Hidden" name="edit" value="0">
<input type="Hidden" name="new" value="1">
					
<table cellpadding="1" cellspacing="8" border="0">
<tr>
	<td class="tit">{$labels[10]}</td>
	<td>
	<div class="cont-block-r-2">
    	<div class="left-bg">
        	<div class="right-bg-3">
            	<input value="{$profile.Company}" type="text" class="textinput-3" name="company" size="12" />
            </div>
         </div>  
    </div>
	</td>
</tr>

culver 10.12.2013 00:21

Вот вся форма:
<form style="padding:0px;margin:0px;" method="post" name="send_vendor_user_form" onsubmit="return check_vendor_new_user();" action="./vendor_edit_user.php">
<input type="Hidden" name="product_id" value="{$product}">
<input type="Hidden" name="edit" value="0">
<input type="Hidden" name="new" value="1">
					
<table cellpadding="1" cellspacing="8" border="0">
<tr>
	<td class="tit">{$labels[10]}</td>
	<td>
	<div class="cont-block-r-2">
    	<div class="left-bg">
        	<div class="right-bg-3">
            	<input value="{$profile.Company}" type="text" class="textinput-3" name="company" size="12" />
            </div>
         </div>  
    </div>
	</td>
</tr>
<tr>
	<td class="tit">{$labels[11]}</td>
	<td>
	<div class="cont-block-r-2">
    	<div class="left-bg">
        	<div class="right-bg-3">
            	<input value="{$profile.www}" type="text" class="textinput-3" name="home_page" size="12" />
            </div>
         </div>  
    </div>	
	</td>	
</tr>
<tr>
	<td class="tit"></td>
	<td>
	&nbsp;&nbsp;&nbsp;
	<input {if $profile.Mtype == 'Mr'}checked{/if} type="radio" name="radioSet" id="option1" value="Mr"  />												
    <label class="chek-title1" for="option1">{$labels[12]}</label>
    <input {if $profile.Mtype == 'Mrs'}checked{/if} type="radio" name="radioSet" id="option2" value="Mrs"  />
    <label class="chek-title1" for="option2">{$labels[13]}</label>
    <input {if $profile.Mtype == 'Ms'}checked{/if} type="radio" name="radioSet" id="option3" value="Ms"  />
    <label class="chek-title1" for="option3">{$labels[14]}</label>		
	<span style="padding-left:80px;" class="tit">{$labels[15]}</span>		
	<div class="cont-block-r" style="padding-right:10px;">
	    <div class="left-bg">
	        <div class="right-bg-2">
	            <input value="{$profile.Position}" type="text" class="textinput-2" name="position" size="12" /></a>
	        </div>
	    </div>  
	</div>																						
	</td>	
</tr>
<tr>
	<td class="tit">{$labels[16]}</td>
	<td>
	<div class="cont-block-r-2">
    	<div class="left-bg">
        	<div class="right-bg-3">
            	<input value="" type="text" class="textinput-3" name="name" size="12" />
            </div>
         </div>  
    </div>	
	</td>	
</tr>
<tr>
	<td class="tit">{$labels[17]}</td>
	<td>
	<div class="cont-block-r-2">
    	<div class="left-bg">
        	<div class="right-bg-3">
            	<input value="" type="text" class="textinput-3" name="second_name" size="12" />
            </div>
         </div>  
    </div>	
	</td>	
</tr>
<tr>
	<td class="tit">{$labels[18]}</td>
	<td>
	<div class="cont-block-r-2">
    	<div class="left-bg">
        	<div class="right-bg-3">
            	<input value="{$profile.Email_1}" type="text" class="textinput-3" name="email" size="12" />
            </div>
         </div>  
    </div>	
	</td>	
</tr>
<tr>
	<td class="tit"></td>
	<td>
	<table style="padding-left:50px;" cellpadding="1" cellspacing="1" border="0">
	<tr>
		<td class="tit">{$labels[19]}</td>
		<td>
        <div class="cont-block-r-3">
            <div class="left-bg">
                <div class="right-bg-4">
                    <input value="{$profile.Phone_1}" type="text" class="textinput-4" name="phone1" size="12" />
                </div>
            </div>  
        </div>		
		</td>
		<td class="tit">{$labels[20]}</td>
		<td>
        <div class="cont-block-r-3">
            <div class="left-bg">
                <div class="right-bg-4">
                    <input value="{$profile.Phone_2}" type="text" class="textinput-4" name="phone2" size="12" />
                </div>
            </div>  
        </div>		
		</td>	
		<td class="tit">{$labels[21]}</td>
		<td>
        <div class="cont-block-r-3">
            <div class="left-bg">
                <div class="right-bg-4">
                    <input value="{$profile.Fax}" type="text" class="textinput-4" name="fax" size="12" />
                </div>
            </div>  
        </div>		
		</td>			
	</tr>
	</table>	
	</td>	
</tr>
<tr>
	<td class="tit">{$labels[22]}</td>
	<td>
	<table cellpadding="1" cellspacing="1" border="0"> 
	<tr>
		<td>
		<div class="cont-block-r">
			<div class="left-bg">
			    <div class="right-bg-2">
			        <input value="{$profile.Country}" type="text" class="textinput-2" name="country" size="12" />
			    </div>
			</div>  
		</div>
		</td>
		<td style="width:12px;"></td>
		<td class="tit">{$labels[23]}</td>
		<td>
		<div class="cont-block-r">
			<div class="left-bg">
			    <div class="right-bg-2">
			        <input value="{$profile.State_Province}" type="text" class="textinput-2" name="state" size="12" />
			    </div>
			</div>  
		</div>
		</td>		
	</tr>
	</table>
	</td>
</tr>
<tr>
	<td class="tit">{$labels[24]}</td>
	<td>
	<table cellpadding="1" cellspacing="1" border="0"> 
	<tr>
		<td>
		<div class="cont-block-r">
			<div class="left-bg">
			    <div class="right-bg-2">
			        <input value="{$profile.City}" type="text" class="textinput-2" name="city" size="12" />
			    </div>
			</div>  
		</div>
		</td>
		<td style="width:12px;"></td>
		<td class="tit">{$labels[25]}</td>
		<td>
		<div class="cont-block-r">
			<div class="left-bg">
			    <div class="right-bg-2">
			        <input value="{$profile.Zip_Postal}" type="text" class="textinput-2" name="zip" size="12" />
			    </div>
			</div>  
		</div>
		</td>		
	</tr>
	</table>
	</td>
</tr>
<tr>
	<td class="tit">{$labels[26]}</td>
	<td>
	<div class="cont-block-r-2">
    	<div class="left-bg">
        	<div class="right-bg-3">
            	<input value="{$profile.Address}" type="text" class="textinput-3" name="adres" size="12" />
            </div>
         </div>  
    </div>	
	</td>	
</tr>
<tr>
	<td class="tit">{$labels[768]}</td>
	<td>
<!--	<div class="cont-block-r-2">
    	<div class="left-bg">
        	<div class="right-bg-3">	-->
					&nbsp;&nbsp;
						<select style="width:195px;" name="level">
						<option value="Supervisor">Supervisor</option>
						<option value="Manager">Manager</option>
						<option value="Operator">Operator</option>
						</select>
<!--            	<input value="{$profile.Address}" type="text" class="textinput-3" name="adres" size="12" />  
            </div>
         </div>  
    </div>	-->
	</td>	
</tr>
<tr>
	<td class="tit">{$labels[8]}</td>
	<td>
	<table cellpadding="1" cellspacing="1" border="0"> 
	<tr>
		<td>
		<div class="cont-block-r">
			<div class="left-bg">
			    <div class="right-bg-2">
						<a rel="tipsy1" title="{$labels[31]}"><input onBlur="h('tipsy1')" onfocus="s('tipsy1')" id="login" value="{$ses.vars.login}" type="text" class="textinput-2" name="logname" size="12" /></a>
						{literal}<script type='text/javascript'>$('#wrapper a[rel=tipsy1]').tipsy({trigger: 'manual', gravity: 'w'});</script>{/literal}
			    </div>
			</div>  
		</div>
		</td>
		<td style="width:12px;"></td>
		<td class="tit">{$labels[9]}</td>
		<td>
		<div class="cont-block-r">
			<div class="left-bg">
			    <div class="right-bg-2">
						<a rel="tipsy2" title="{$labels[32]}"><input onBlur="h('tipsy2')" onfocus="s('tipsy2')" type="password" class="textinput-2" name="pas" size="12" /></a>
						{literal}<script type='text/javascript'>$('#wrapper a[rel=tipsy2]').tipsy({trigger: 'manual', gravity: 'w'});</script>{/literal}														
			    </div>
			</div>  
		</div>
		</td>		
	</tr>
	</table>
	</td>
</tr>		
<tr>
	<td class="tit">{$labels[767]}</td>
	<td>	
		<div style="margin-left: 10px;">
				{section name=i loop=$products}
					<input type="checkbox" name="products_cb[{$products[i].ID}]" class="svuf_checkbox" />&nbsp;{$products[i].Public_Name}&nbsp;  <!--  checked="checked"  -->
				{/section}
		</div>		
	</td>	
</tr>					
<tr>
	<td colspan="2" align="center">
		<input src="./img/sub.gif" type="Image">
	</td>
</tr>
</table>
</form>

culver 10.12.2013 00:23

JS что, в глубине дивов инпуты не видит?

culver 10.12.2013 01:36

спасибо


Часовой пояс GMT +3, время: 11:49.